package com.managerProvider.controller;

import com.alibaba.fastjson.JSON;
import entity.ResponseMessage;
import entity.Store;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import service.StoreService;

@RestController
@RequestMapping("/store")
@CrossOrigin
public class StoreController {
    @Autowired
    private StoreService storeService;

    private Logger logger = Logger.getLogger(this.getClass());

    /**
     * 选择所有商店
     *
     * @param store 商店
     * @return {@link String}
     */
    @RequestMapping("/selectAllStore")
    public String selectAllStore(@RequestBody Store store) {
        ResponseMessage allStore = storeService.findAllStore(store);
        return JSON.toJSONStringWithDateFormat(allStore, "yyyy-MM-dd HH:mm:ss");
    }

    /**
     * 更新商店
     *
     * @param store 商店
     * @return {@link String}
     */
    @RequestMapping("/updateStore")
    public String updateStore(@RequestBody Store store) {
        ResponseMessage msg = storeService.updateStore(store);
        return JSON.toJSONString(msg);
    }
}
